package com.oa.controller.user;

import com.oa.pojo.Emp;
import com.oa.service.user.UserService;
import com.oa.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author: 一拳超人
 * @Date: 2021/10/2 16:30
 */
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 登陆验证
     *
     * @param emp 用户信息
     * @return 验证结果
     */
    @PostMapping("/login")
    public SysResult userLogin(@RequestBody Emp emp) {
        emp = userService.login(emp);
        if (emp == null) {
            return SysResult.fail("用户名或密码错误!");
        }
        if (!emp.getEmpStatus()){
            return SysResult.fail("该账号已停用!");
        }
        return SysResult.success(emp);
    }

    /**
     * 用户管理模块根据员工姓名查询员工信息
     *
     * @param name 姓名
     * @return SysResult结果
     */
    @GetMapping("/selectEmpInfo")
    public SysResult selectEmpInfo(String name) {
        List<Emp> empList = userService.selectEmpInfo(name);
        if (empList.size() == 0) {
            return SysResult.fail("没有此员工!");
        }
        return SysResult.success(empList);
    }

    /**
     * 用户管理模块员工个人信息查询
     *
     * @param empId 员工编号
     * @return SysResult结果
     */
    @GetMapping("/selectOneself")
    public SysResult selectOneself(String empId) {
        return SysResult.success(userService.selectOneself(empId));
    }

    /**
     * 用户管理模块个人信息修改
     *
     * @param emp 要修改的员工信息
     * @return 修改结果
     */
    @PutMapping("/updateOneselfInfo")
    public SysResult updateOneselfInfo(@RequestBody Emp emp) {
        return SysResult.success(userService.updateOneselfInfo(emp));
    }

    @PutMapping("/changeInfo/password")
    public SysResult changeOneselfPassword(@RequestBody Emp emp) {
        System.out.println(emp);
        return SysResult.success(userService.changeOneselfPassword(emp));
    }
}
